package com.betterjr.modules.customer.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.betterjr.common.exception.BytterTradeException;
import com.betterjr.common.service.BaseService;
import com.betterjr.common.utils.Collections3;
import com.betterjr.mapper.pagehelper.Page;
import com.betterjr.modules.bank.entity.BankProperty;
import com.betterjr.modules.customer.dao.SysNapsBankCodeMapper;
import com.betterjr.modules.customer.entity.SysNapsBankCode;

/****
 * 查询银行关联的联行号信息
 * @author hubl
 *
 */
@Service
public class SysNapsBankCodeService extends BaseService<SysNapsBankCodeMapper, SysNapsBankCode> {

    @Autowired
    private BankPropertyService bankPropertyService;

    public Page<SysNapsBankCode> findSysBankCodeList(Map<String, Object> anParam) {
        final Map<String, Object> anMap = new HashMap<String, Object>();
        if (StringUtils.isNotBlank((String) anParam.get("bankName"))) {
            anMap.put("LIKEorgFullName", "%" + anParam.get("bankName") + "%");
        }
        return this.selectPropertyByPage(anMap, 1, 10, false);
    }

    /**
     * 
     * @Title: queryAllBankProperty 
     * @Description: TODO(查询所有银行属性信息) 
     * @param @return 参数说明 
     * @return List<BankProperty> 返回类型 
     * @throws 
     * @author chenlq
     * @date 2018年7月12日 下午5:06:21
     */
    public List<BankProperty> queryAllBankProperty() {
        return bankPropertyService.selectAll();
    }

    /***
     * 银行全称是否一致
     * @param anPaySysNum
     * @param anBankName
     */
    public void checkBankCode(String anPaySysNum, String anBankName) {
        final SysNapsBankCode bankCode = this.selectByPrimaryKey(anPaySysNum);
        if (bankCode != null) {
            if (!StringUtils.equalsIgnoreCase(anBankName, bankCode.getOrgFullName())) {
                throw new BytterTradeException("所填银行全称不存在");
            }
        } else {
            throw new BytterTradeException("请选择银行全称");
        }
    }

    public SysNapsBankCode findSysBankCodeInfoByBankName(String anBankName) {
        final List<SysNapsBankCode> codeList = this.selectByProperty("orgFullName", anBankName);
        return Collections3.getFirst(codeList);
    }

}
